package com.hnhuas.salary.modules.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hnhuas.salary.common.utils.PageUtils;
import com.hnhuas.salary.common.utils.R;
import com.hnhuas.salary.common.validator.ValidatorUtils;
import com.hnhuas.salary.modules.admin.entity.SalaryNoticeEntity;
import com.hnhuas.salary.modules.admin.entity.SalaryTitleTypeEntity;
import com.hnhuas.salary.modules.admin.service.SalaryTitleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wf.jwtp.annotation.RequiresRoles;

import javax.servlet.http.HttpServletRequest;
import java.awt.geom.QuadCurve2D;
import java.util.List;
import java.util.Map;

/**
 * 栏目类型接口
 * @author lwt
 * @email 1520644927@qq.com
 * @date 2019-09-11 18:03:11
 */
@RestController
@RequestMapping("/admin/title")
public class SalaryTitleTypeController {

    @Autowired
    private SalaryTitleTypeService salaryTitleTypeService;

    /**
     * 获取所有标题
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = salaryTitleTypeService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 根据收入与支出类型查询标题
     */
    @GetMapping("/findByIncome")
    public R findByIncome(){
        QueryWrapper<SalaryTitleTypeEntity> queryPage = new QueryWrapper<>();
        List<SalaryTitleTypeEntity> list = salaryTitleTypeService.list(queryPage);
        return R.ok().put("data",list);
    }

    /**
     * 保存标题
     * @param salaryTitleType
     * @param request
     * @return
     */
    @PostMapping("/save")
    @RequiresRoles("admin")
    public R save(@RequestBody SalaryTitleTypeEntity salaryTitleType, HttpServletRequest request){
        salaryTitleTypeService.save(salaryTitleType);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresRoles("admin")
    public R update(@RequestBody SalaryTitleTypeEntity salaryTitleType){
        ValidatorUtils.validateEntity(salaryTitleType);
        salaryTitleTypeService.updateById(salaryTitleType);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresRoles("admin")
    public R delete(@PathVariable("id") Long id){
        salaryTitleTypeService.removeById(id);

        return R.ok();
    }
}
